import { notify } from '@/widgets'
import { activeOrOpenFloatPane, openFloatPane, registerAppMenu } from '@/app'
import { listSelect } from '@/common/list-select'
import { getEntity, getEntityList } from '../../base'
import type { AircraftType } from '../types'
import AircraftTypeView from './AircraftTypeView.vue'

export function showAircraftTypeView(id: string) {
  const acType = getEntity<AircraftType>('AircraftType', id)
  if (!acType) {
    notify.error({ content: `机型${id}不存在` })
    return
  }
  const key = `@@ac-type-view-{id}`
  activeOrOpenFloatPane({
    key,
    name: '机型 | ' + id,
    icon: 'mas-icon-AircraftType',
    component: AircraftTypeView,
    props: { id }
  })
}

export function selectAircraftTypeView() {
  const data = getEntityList<AircraftType>('AircraftType')
  listSelect<AircraftType>({
    title: '选择机型',
    data,
    icon: 'mas-icon-AircraftType',
    getItemName: (e) => e.id,
    callback: (t) => showAircraftTypeView(t.id)
  })
}

export function setupAircraftTypeView() {
  registerAppMenu({
    path: '模型/{mas-icon-AircraftType}查看机型信息',
    onClick: selectAircraftTypeView
  })
}
